from flask import Flask, request, g
import requests
# 创建Flask实例app,（WSGI 是一套协议，使 Web 应用和服务器交互跟通顺）
from flask_httpauth import HTTPBasicAuth
from flask_sqlalchemy import SQLAlchemy
from flask_cors import CORS


app = Flask(__name__)
auth = HTTPBasicAuth
CORS(app)

# /,  /test, /test/<value>,给app定义路由,methods=可指定请求的方法
# @app.route("/", methods=['POST'])
@app.route("/", methods=['GET'])
def hello_world():
    # 返回数据类型string、tuple、dict,对应text/html; charset=utf-8 和 application/json
    # return "<h1>hello,world!</h1>"
    # return ("<p>Hello, World!</p>")
    return {"msg": "<h1>hello,world!</h1>"}

# 可以通过 http://127.0.0.1:5000/param?a=b&c=k 来发送两个参数 a=b 和 c=k
@app.route("/param", methods=["post"])
def get_param():
    # print(request.json)
    return request.args

@app.route("/test/<value>")
def get_var(value):
    return value

@app.route("/login")
def login():
    return {"msg": "login OK", "data": "null"}

@app.route("/register")
def register():
    return {"msg": "register OK", "data": "null"}

@app.route("/get_infor")
def get_information():
    return {"msg": "get_information OK", "data": "null"}

#------------------------------------
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:123456@localhost:3306/test'

db =SQLAlchemy(app)

#------------------------------------

if __name__ == '__main__':
    app.run(debug=True)